
package org.apache.solr.highlight;

import java.net.URL;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrInfoMBean;

/**
 *
 * @since solr 1.3
 */
public abstract class HighlightingPluginBase implements SolrInfoMBean {

    protected long numRequests;
    protected SolrParams defaults;

    public void init(NamedList args) {

        if(args != null) {
            Object o = args.get("defaults");
            if(o != null && o instanceof NamedList) {
                defaults = SolrParams.toSolrParams((NamedList)o);
            }
        }
    }

    // SolrInfoMBeans methods
    @Override
    public String getName() {
        return this.getClass().getName();
    }

    @Override
    public abstract String getDescription();

    @Override
    public abstract String getSource();

    @Override
    public String getVersion() {
        return getClass().getPackage().getSpecificationVersion();
    }

    @Override
    public Category getCategory() {
        return Category.HIGHLIGHTING;
    }

    @Override
    public URL[] getDocs() {
        return null;  // this can be overridden, but not required
    }

    @Override
    public NamedList getStatistics() {

        NamedList<Long> lst = new SimpleOrderedMap<>();
        lst.add("requests", numRequests);

        return lst;
    }
}
